const Realm = require('realm');

// 新建表模型
const PersonSchema = {
    name: 'Person',
    properties: {
        name: 'string',
        email: 'string',
        uuid: 'string',
        remark: 'string'
    }
};

let realm = new Realm({schema: [PersonSchema]});

realm.write(() => {
    realm.create('Person', {
        uuid:"test",
        name: "白衣凡尘",
        email: "710335997@qq.com",
        remark: "佛曰：因果循环、往生极乐"
    });
})

export default {

    add(name,object){
        realm.write(() => {
            realm.create(name, object);
        })
    },

    read(name,filter){
        var data;
        if(!filter){
            data=realm.objects(name);
        }else{
            data= data.filtered(filter);
        }
        return data;
    },

    mime(){
        debugger
        var data=realm.objects("Person")
        if(data){
            return data[0];
        }else{
            return {}
        }
    }


}